package com.apply.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import com.apply.inter.MyHandShakeInterceptor;
import com.apply.service.impl.WebSocketService;


@Component
@EnableWebSocket
public class MyWebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer {

    @Autowired
    WebSocketService handler;
    
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
          
    	
        try {
			//添加websocket处理器，添加握手拦截
			webSocketHandlerRegistry.addHandler(handler, "/ws").addInterceptors(new MyHandShakeInterceptor());

			//添加websocket处理器，添加握手拦截� 
			webSocketHandlerRegistry.addHandler(handler, "/ws/sockjs").addInterceptors(new MyHandShakeInterceptor()).withSockJS();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			
		}
    }
}
